package com.yy.tech.data.provider.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author yy
 * @date 2022/4/18
 * @description: TODO
 */
public class SecretRule {
    private String clsName;
    private String requestUri;
    private String encoder ;
    private String decoder ;
    private List<String> encrypts;
    private List<String> excludes;

    public String getClsName() {
        return clsName;
    }

    public void setClsName(final String clsName) {
        this.clsName = clsName;
    }

    public String getRequestUri() {
        return requestUri;
    }

    public void setRequestUri(final String requestUri) {
        this.requestUri = requestUri;
    }

    public String getEncoder() {
        return encoder;
    }

    public void setEncoder(final String encoder) {
        this.encoder = encoder;
    }

    public String getDecoder() {
        return decoder;
    }

    public void setDecoder(final String decoder) {
        this.decoder = decoder;
    }

    public List<String> getEncrypts() {
        return encrypts;
    }

    public void setEncrypts(final List<String> encrypts) {
        this.encrypts = encrypts;
    }

    public List<String> getExcludes() {
        return excludes;
    }

    public void setExcludes(final List<String> excludes) {
        this.excludes = excludes;
    }

    @JsonIgnore
    public boolean match(FindCondition condition){
        boolean result = condition.matchBase(this);
        if (result){
            FindCondition.FindType type = condition.getType();
            List<String> names = null;
            switch (type){
                case encrypt:
                    names = encrypts;
                    break;
                case exclude:
                    names = excludes;
                    break;
            }
            if (!CollectionUtils.isEmpty(names) && names.contains(condition.getName())){
                return true;
            }
        }
        return false;
    }
}
